React Toast Component 您所在的位置:网站首页 toast definition React Toast Component

React Toast Component

2022-12-30 22:23| 来源: 网络整理| 查看: 265

Support CoreUI Development

CoreUI is an MIT-licensed open source project and is completely free to use. However, the amount of effort needed to maintain and develop new features for the project is not sustainable without proper financial backing.

You can support our Open Source software development in the following ways:

Buy the CoreUI PRO, and get access to PRO components, and dedicated support.Hire Us! We create stunning designs, high-conversion landing pages, functional mobile apps and reliable web services – everything you need to offer your products or services online and always stay a tap away from your customers.Give us a star ⭐️ on Github.React Toast Component

Push notifications to your visitors with a toast, a lightweight and easily customizable alert message.

Other frameworks

CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.

Angular ToastBootstrap ToastVue Toast

React toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems. They’re built with flexbox, so they’re easy to align and position.

Overview#

Things to know when using the toast plugin:

Toasts are opt-in for performance reasons, so you must initialize them yourself.Toasts will automatically hide if you do not specify autohide: false.Examples#Basic#

To encourage extensible and predictable toasts, we recommend a header and body. Toast headers use display: flex, allowing easy alignment of content thanks to our margin and flexbox utilities.

Toasts are as flexible as you need and have very little required markup. At a minimum, we require a single element to contain your "toasted" content and strongly encourage a dismiss button.

12 3 12 13 14 CoreUI for React.js15 7 min ago16 17 Hello, world! This is a toast message.181const [toast, addToast] = useState(0)2const toaster = useRef()3const exampleToast = (4 5 6 15 16 17 CoreUI for React.js18 7 min ago19 20 Hello, world! This is a toast message.21 22)23return (24 25 addToast(exampleToast)}>Send a toast26 27 28)Translucent#

Toasts are slightly translucent to blend in with what's below them.

12 3 12 13 14 CoreUI for React.js15 7 min ago16 17 Hello, world! This is a toast message.18Stacking#

You can stack toasts by wrapping them in a toast container, which will vertically add some spacing.

12 3 4 13 14 15 CoreUI for React.js16 7 min ago17 18 Hello, world! This is a toast message.19 20 21 22 31 32 33 CoreUI for React.js34 7 min ago35 36 Hello, world! This is a toast message.37 38Custom content#

Customize your toasts by removing sub-components, tweaking them with utilities, or by adding your own markup. Here we've created a simpler toast by removing the default , adding a custom hide icon from CoreUI Icons, and using some flexbox utilities to adjust the layout.

12 3 Hello, world! This is a toast message.4 5 6

Alternatively, you can also add additional controls and components to toasts.

12 3 Hello, world! This is a toast message.4 5 6 Take action7 8 9 Close10 11 12 13Color schemes#

Building on the above example, you can create different toast color schemes with our color and background utilities. Here we've set color="primary" and added .text-white class to the , and then set white property to our close button. For a crisp edge, we remove the default border with .border-0.

12 3 Hello, world! This is a toast message.4 5 6Customizing#CSS variables#

React toasts use local CSS variables on .toast for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.

1--cui-toast-padding-x: #{$toast-padding-x};2--cui-toast-padding-y: #{$toast-padding-y};3--cui-toast-spacing: #{$toast-spacing};4--cui-toast-max-width: #{$toast-max-width};5--cui-toast-font-size: #{$toast-font-size};6--cui-toast-color: #{$toast-color};7--cui-toast-bg: #{$toast-background-color};8--cui-toast-border-width: #{$toast-border-width};9--cui-toast-border-color: #{$toast-border-color};10--cui-toast-border-radius: #{$toast-border-radius};11--cui-toast-box-shadow: #{$toast-box-shadow};12--cui-toast-header-color: #{$toast-header-color};13--cui-toast-header-bg: #{$toast-header-background-color};14--cui-toast-header-border-color: #{$toast-header-border-color};How to use CSS variables#1const vars = { 2 '--my-css-var': 10,3 '--my-another-css-var': "red" 4}5return ...SASS variables#1$toast-max-width: 350px;2$toast-padding-x: .75rem;3$toast-padding-y: .5rem;4$toast-font-size: .875rem;5$toast-color: unset;6$toast-background-color: rgba($white, .85);7$toast-border-width: $border-width;8$toast-border-color: var(--cui-border-color-translucent);9$toast-border-radius: $border-radius;10$toast-box-shadow: $box-shadow;11$toast-spacing: $container-padding-x;12 13$toast-header-color: $gray-600;14$toast-header-background-color: rgba($white, .85);15$toast-header-border-color: rgba($black, .05);API#CToast#1import { CToast } from '@coreui/react'2// or3import CToast from '@coreui/react/src/components/toast/CToast'PropertyDescriptionTypeDefaultanimationApply a CSS fade transition to the toast.booleantrueautohideAuto hide the toast.booleantrueclassNameA string of all className you want applied to the base component.string-colorSets the color context of the component to one of CoreUI’s themed colors.'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string-delayDelay hiding the toast (ms).number5000onCloseCallback fired when the component requests to be closed.(index: number) => void-onShowCallback fired when the component requests to be shown.(index: number) => void-visibleToggle the visibility of component.booleanfalseCToastHeader#1import { CToastHeader } from '@coreui/react'2// or3import CToastHeader from '@coreui/react/src/components/toast/CToastHeader'PropertyDescriptionTypeDefaultclassNameA string of all className you want applied to the base component.string-closeButtonAutomatically add a close button to the header.boolean-CToastBody#1import { CToastBody } from '@coreui/react'2// or3import CToastBody from '@coreui/react/src/components/toast/CToastBody'PropertyDescriptionTypeDefaultclassNameA string of all className you want applied to the base component.string-CToastClose#1import { CToastClose } from '@coreui/react'2// or3import CToastClose from '@coreui/react/src/components/toast/CToastClose'PropertyDescriptionTypeDefaultactiveToggle the active state for the component.boolean-classNameA string of all className you want applied to the base component.string-componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass | FunctionComponent-disabledToggle the disabled state for the component.boolean-hrefThe href attribute specifies the URL of the page the link goes to.string-shapeSelect the shape of the component.'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string-sizeSize the component small or large.'sm' | 'lg'-typeSpecifies the type of button. Always specify the type attribute for the element.Different browsers may use different default types for the element.'button' | 'submit' | 'reset'-variantSet the button variant to an outlined button or a ghost button.'outline' | 'ghost'-whiteChange the default color to white.boolean-CToaster#1import { CToaster } from '@coreui/react'2// or3import CToaster from '@coreui/react/src/components/toast/CToaster'PropertyDescriptionTypeDefaultclassNameA string of all className you want applied to the base component.string-placementDescribes the placement of your component.'top-start' | 'top' | 'top-end' | 'middle-start' | 'middle' | 'middle-end' | 'bottom-start' | 'bottom' | 'bottom-end' | string-pushAdds new CToast to CToaster.ReactElement-


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有